 (
    function (factory) {
        if (typeof define === "function" && define.amd) {

            // AMD. Register as an anonymous module.
            define(["jquery", "./version"], factory);
        } else {

            // Browser globals
            factory(jQuery);
        }
    }
        (
        function ($) {
            var AppNav = function (op) {
                var _options = op;
              
                function init() {
                    try {
                        //set user list
                        var users = _options.users;
                        var applist = $('.user-list')
                        var appTpl = $('.user-list .user-template')
                        appTpl.remove();
                        // $(userlist).e(appTpl)
                        if (users) {
                            users.forEach(function (app) {
                                var html = appTpl.clone();
                               html.find('.user-link').attr('src', app.url)
                               html.find('.user-name').html(app.name)
                               html.find('.user-password').html(app.password) 
                               html.find('.user-right').html(app.right)                           
                               html.appendTo(applist);                              
                            });
                        }
                
                    } catch(e){

                    }

                }
                this.init = init;
            }

            AppNav.defaultOptions = {
                'emptyOnInit': true
            }
                    //新增管理员
                    $(function() {
                    $('#doc-prompt-toggle').on('click', function() {
                        $('#my-prompt').modal({
                        relatedTarget: this,
                        onConfirm: function(e) {
                            alert('你输入的是：' + e.data || '')
                        },
                        onCancel: function(e) {}
                        });
                    });

                    //编辑管理员信息，暂时没用

                    $('#doc-prompt-edit').on('click', function() {
                        $('#my-edit').modal({
                        relatedTarget: this,
                        onConfirm: function(e) {
                            alert('你输入的是：' + e.data || '')
                        },
                        onCancel: function(e) {}
                        });
                    });

                    //删除管理员信息，暂时没用

                    $('#doc-modal-list').find('.ms-icon-close').add('#doc-confirm-toggle').
                        on('click', function() {
                        $('#my-confirm').modal({
                            relatedTarget: this,
                            onConfirm: function(options) {
                            var $link = $(this.relatedTarget).prev('a');
                            var msg = '你要删除的链接 ID 为 ' + $link.data('id') ;         
                            alert(msg);
                            },
                            // closeOnConfirm: false,
                            onCancel: function() {}
                        });
                        });

                    });
                    var appNavInit = function () {
                        $.get('mockdata/user.json', function (data) {
                            var users = data.users;
                            $.get('user.html', function (tpl) {
                                var op = AppNav.defaultOptions;
                                op['users'] = users;
                                op['template'] = tpl;
                                var appNav = new AppNav(op);
                                instance = appNav;
                                instance.init();                                
                            })
                        })
                    }
            $(appNavInit)
        }       
        )        
)